/*
 * @Author: zjf
 * @Date: 2023-11-29 16:26:47
 * @LastEditors: JenClint
 * @LastEditTime: 2023-12-29 14:31:37
 * @Description: 图片预览
 */
export default function() {
  return {
    data() {
      return {
        imgVisible: false,
        filesid: "", // 选择预览图片文件id
        imgsList: [], // 当前查看的图片列表
      };
    },
    methods: {
      async handlePreview(filesid) {
        this.imgsList = await this.GET_FOLDER_IMG(filesid);
        if (this.imgsList.length) {
          this.imgVisible = true;
        } else {
          this.$message.error("未查询到图片");
        }
      },
      closeImgViewer() {
        this.imgVisible = false;
      },
      /** 获取项目照片 */
      async GET_FOLDER_IMG(folderId) {
        if (folderId) {
          const api = window.$crud(`system/annexesfile/${folderId}/list`);
          const list = await this.$awaitWraper(api.getInfo());
          if (list.length) {
            const imageList = list.map(
              (t) =>
                `${this.apiUrl}system/annexesfile/preview/${t.f_Id}?token=${this.token}`
            );
            return imageList;
          }
        }
        return [];
      },
    },
  };
}
